package org.example.extension.beanFactoryPostProcessor;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class CustomBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry){
        // 注册一个BeanDefinition
        System.out.println("CustomBeanDefinitionRegistryPostProcessor.postProcessBeanDefinitionRegistry");
        AbstractBeanDefinition definition = BeanDefinitionBuilder
                .genericBeanDefinition(BeanFactoryDemo2.class)
                .getBeanDefinition();
        registry.registerBeanDefinition("beanFactoryDemo2", definition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory){
        // custom logic here
    }
}
